<template>
  <div>
    <el-card style="min-width: 1200px">
      <el-row>
        <div class="tableSelectWrap">
          <el-form
            ref="childOverviewForm"
            :model="commandForm"
            label-width="100px"
          >
            <el-col :span="7">
              <el-form-item label="选择时间" prop="date">
                <el-date-picker
                  v-model="commandForm.date"
                  type="daterange"
                  :default-time="['00:00:00', '23:59:59']"
                  unlink-panels
                  style="width: 100%"
                  :picker-options="pickerOptions"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :clearable="false"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="所属商户" prop="memberId">
                <el-select
                  v-model="commandForm.memberId"
                  class="leftSelect"
                  style="width: 100%"
                  placeholder="请选择商户"
                >
                  <el-option
                    v-for="item of merchaList"
                    :key="item.id"
                    :label="item.memberName"
                    :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6" :offset="2" style="min-width: 170px">
              <el-button
                class="width120"
                @click="resetForm('childOverviewForm')"
                >重置</el-button
              >
              <el-button
                type="primary"
                class="width120"
                @click="
                  () => {
                    this.dataForm = JSON.parse(
                      JSON.stringify(this.commandForm)
                    );
                    this.handleQuery();
                  }
                "
                >查询</el-button
              >
            </el-col>
          </el-form>
        </div>
      </el-row>
      <el-row> </el-row>
    </el-card>
    <el-card
      class="textBox"
      style="min-width: 1200px; margin-bottom: 15px; margin-top: 15px"
    >
      <span class="numBox">
        <span>收入</span>
        <span class="symbol">￥</span>
        <span class="num">{{ statisticInfo.fmtIncomeTotalAmount || 0.0 }}</span>
      </span>
      <span class="numBox">
        <span>支出</span>
        <span class="symbol">￥</span>
        <span class="num">{{ statisticInfo.fmtPayoutTotalAmount || 0.0 }}</span>
      </span>
      <span class="numBox">
        <span>手续费</span>
        <span class="symbol">￥</span>
        <span class="num">{{ statisticInfo.fmtFeeTotalAmount || 0.0 }}</span>
      </span>
    </el-card>
    <el-card style="min-width: 1200px">
      <div class="switch">
        <el-switch v-model="isFixedTableH" inactive-text="固定表头">
        </el-switch>
      </div>
      <el-table :data="dataList" :height="fixedTableHeight">
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <!-- <el-table-column show-overflow-tooltip prop="gmtCreated" align="center" label="创建时间">
          <template slot-scope="scope">
          <div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
            {{scope.row.gmtCreated?scope.row.gmtCreated:'-'}}
          </div>
        </template>
        </el-table-column> -->
        <el-table-column
          show-overflow-tooltip
          prop="memberName"
          align="center"
          label="商户名称"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.memberName ? scope.row.memberName : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="memberNo"
          align="center"
          label="商户ID"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.memberNo ? scope.row.memberNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="incomeAmountTotal"
          sortable
          align="center"
          label="收入/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.fmtIncomeTotalAmount ? scope.row.fmtIncomeTotalAmount : "-"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="payoutAmountTotal"
          sortable
          align="center"
          label="支出/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.fmtPayoutTotalAmount ? scope.row.fmtPayoutTotalAmount : "-"
              }}
            </div>
          </template>
        </el-table-column>
         <el-table-column
          show-overflow-tooltip
          prop="payoutAmountTotal"
          sortable
          align="center"
          label="手续费/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.fmtFeeTotalAmount ? scope.row.fmtFeeTotalAmount : "-"
              }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column
          show-overflow-tooltip
          prop="memberClass"
          align="center"
          label="商户类型"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.memberType ? memberTypeObj[scope.row.memberType] : "-"
              }}
            </div>
          </template>
        </el-table-column> -->
        
      </el-table>
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :current-page="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>
  </div>
</template>

<script>
import mixins from "@/mixins/mixin";
import pickerOptions from "@/utils/pickerOptions";
export default {
  name: "childOverview",
  mixins: [mixins],
  components: {
  },
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/api/member/view/searchByPage",
        createdIsNeed: false,
      },
      memberTypeObj: {
        1: "政府机构",
        2: "国营企业",
        3: "私营企业",
        4: "外资企业",
        5: "个体工商户",
        6: "事业单位",
      },
      pickerOptions,
      commandForm: {
        appId: this.$store.state.appId || "",
        date: [
          this.$moment().startOf("day").format("YYYY-MM-DD HH:mm:ss"),
          this.$moment().endOf("day").format("YYYY-MM-DD HH:mm:ss"),
        ],
        merchant: [],
        memberId: "",
      },
      merchaList: [],

      dataList: [],
      statisticInfo: {},
    };
  },
  created() {
    //获取应用列表信息
      this.$http.get("/api/app/get").then((res) => {
        let appItem = res.data.find(
          (item) => item.id == this.$store.state.appId
        );
        this.merchaList = [
          {
            id: "",
            memberName: appItem.appName,
          },
        ];
        this.getmerList();
      });
    this.dataForm = JSON.parse(JSON.stringify({
      ...this.commandForm,
      date:""
    }));
    this.handleQuery();
  },
  methods: {
    getmerList() {
      this.$http
        .get("/api/merchant/memberbase/listByAppIdAndTreeChain")
        .then((res) => {
          this.merchaList = [
            ...this.merchaList,
            ...res.data
          ]
          // this.commandForm.memberId = this.$store.state.appId;
        });
    },
    handleQuery() {
      if (this.dataForm.date && this.dataForm.date.length) {
        this.dataForm.gmtCreatedBegin = this.$moment(
          this.dataForm.date[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.dataForm.gmtCreatedEnd = this.$moment(
          this.dataForm.date[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      if (this.dataForm.merchant.length) {
        this.dataForm.id = this.dataForm.merchant.at(-1);
      }
      this.getDataList();
      this.getInfo();
    },
    getInfo() {
      this.$http
        .post("/api/member/view/statistics", {
          ...this.dataForm,
        })
        .then((res) => {
          if (res.code === "0000") {
            this.statisticInfo = res.data;
          }
        });
    },
    getCurrentDate() {
      this.commandForm.date = [
        this.$moment().startOf("day").format("YYYY-MM-DD HH:mm:ss"),
        this.$moment().endOf("day").format("YYYY-MM-DD HH:mm:ss"),
      ];
    },
  },
  watch: {
    "$store.state.testLine": {
      handler() {
        if (this.$route.name == this.$options.name) {
          this.getDataList();
          this.getInfo();
        }
      },
    },
    deep: true,
  },
};
</script>

<style scoped lang="scss">
.switch {
  margin-bottom: 20px;
}
.ml {
  margin-left: 50px;
}
:deep(.el-form-item) {
  margin-bottom: 0;
}
</style>
